<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    html{
      background: #f1f1f1;
    }
  </style>
</head>
<body>
  <div id="header" onclick="location.href='./video.html'"></div>
  <div id="list"></div>
  <button onclick="addAction()">add</button>
  <script type="text/javascript" src="./components/item/index.js"></script>
  <script type="text/javascript" src="./components/header/index.js"></script>
  <script type="text/javascript">
    
    let array = []
    function emit(index){
      array[index].isChange = !array[index].isChange
      renderList()
    }
    function deleteAction(index){
      array.splice(index,1)
      renderList()
    }
    function addAction(){
      array.push({
        text:Math.random(),
        isChange:false,
      })
      renderList()
    }
    function renderList(){
      document.getElementById("list").innerHTML = ''
      var fragment = document.createDocumentFragment()
      array.forEach((item,index)=>{
        fragment.appendChild(ItemComponent.createDom({
          item:item,
          index:index,
          emit:function(){
            emit(index)
          },
          delete:function(e){
            e.stopPropagation()
            deleteAction(index)
          }
        }))
      })
      document.getElementById("list").appendChild(fragment)
    }
    function renderHeader(){
      document.getElementById("header").appendChild(HeaderComponent.createDom({title:"头部"}))
    }

    setTimeout(() => {
      for (let i = 0; i < 10; i++) {
        array.push({
          text:Math.random(),
          isChange:false,
        })
      }
      renderList()
    }, 1000);
    renderHeader()
  </script>
</body>
</html>